﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.Activities;

namespace Anagramme.Activities.BusinessRules.Tests
{
    [TestClass]
    public class NotBusyWithPlayerNameActivityTests
    {
        [TestMethod]
        public void PlayerNameEmptyReturnsFalse()
        {            
            bool expected = false;
            IDictionary<string, object> actual = ExecuteWorkflow(false, string.Empty);

            Assert.IsNotNull(actual);
            Assert.AreEqual(1, actual.Count);
            Assert.AreEqual(expected, actual["ReturnValue"]);
        }

        [TestMethod]
        public void IsBusyReturnsFalse()
        {
            bool expected = false;
            IDictionary<string, object> actual = ExecuteWorkflow(true, "name");

            Assert.IsNotNull(actual);
            Assert.AreEqual(1, actual.Count);
            Assert.AreEqual(expected, actual["ReturnValue"]);
        }

        [TestMethod]
        public void NotBusyAndPlayerNameNotEmptyReturnsTrue()
        {
            bool expected = true;
            IDictionary<string, object> actual = ExecuteWorkflow(false, "name");

            Assert.IsNotNull(actual);
            Assert.AreEqual(1, actual.Count);
            Assert.AreEqual(expected, actual["ReturnValue"]);
        }

        protected IDictionary<string, object> ExecuteWorkflow(bool isBusy, string playerName)
        {
            IDictionary<string, object> arguments = new Dictionary<string, object>
            {
                {"IsBusy", isBusy },
                {"PlayerName", playerName }
            };

            NotBusyWithPlayerNameActivity activity = new NotBusyWithPlayerNameActivity();
            IDictionary<string, object> returnValue = WorkflowInvoker.Invoke(activity, arguments);

            return returnValue;
        }
    }
}
